<?php
function leftpanel($style,$n=null){
	$user=$_SESSION["user"];
	$str="";
	$style=strtoupper($style);
	$panel=array(
		"RW"=>array("始发站","中转站","目的站","箱方案","始发站->中转站","中转站->目的站","<font color='blue'>数据查询</font>","<font color='blue'>用户管理</font>","<font color='blue'>发布信息</font>"),
		"RW_w"=>array("/railway/list_s.php","/railway/list_z.php","/railway/list_e.php","/railway/list_box.php","/railway/list_sz.php","/railway/list_ze.php","/railway/list.php","/user/list.php","/bulletin/bl_list.php")
		);
	foreach ($panel[$style] as $key=>$value) {
		if(($key+1)==$n){
			$str.='<li><a href="#"><span class="actiove">'.$panel[$style][$key].'</span></a></li>';
		}else{
			if($panel[$style][$key]&& $panel[$style][$key]!="")
			$str.='<li><a href="'.$panel[$style."_w"][$key].'"><span>'.$panel[$style][$key].'</span></a></li>';
		}
	}
	return $str;
}
function getlastday($day){
	$t1   =   strtotime($day);
	if(!$t1)return"无法计算";
	$t2   =   strtotime(date("Y-m-d H:i:s"));
	$t=$t1-$t2;
	if($t <0)
	$t=$t*(-1);
	$day=$t/3600/24;
	return ceil($day);
}
function score_format($number){
	$number=number_format($number,6);
	//$number=$number*1000000/1000000;
	$point   = '.';
	$pos = strpos($number, $point);
	if ($pos === false) {
		return $number;
	}else{
		$l= substr($number,-1);
		while($l==="0"){
			$number = substr($number, 0, -1);
			$l= substr($number,-1);
			if($l===".")$number = substr($number, 0, -1);
		}
		return $number;
	}	
}

function split_str($str,$num){
	//$len = strlen($str);
	$len =(strlen($str) + mb_strlen($str,'UTF8')) / 2;
	$suffix = '';
	$c_num=0;
	$c_array=array(0,0,1,1,2,2);//汉字长度微调系数
	if($len > $num){
		$len = $num;
		$suffix = ' ... ';
		for ($idx = 0; $idx < $len; ){
			if (ord($str[$idx]) > 0x7f){
				$idx += 3;
				$c_num++;
			}else{
				$idx++;
			}
		}
		if ($c_num>5)$c_array[$c_num]=0;
		return substr($str, 0, $idx+$c_array[$c_num]*3).$suffix;
	}else{
		return $str;
	}
}
function get_array ($file,$n=null) {
	$filename = "../resource/$file.csv";
	$read = @fopen($filename, "r") or die("Couldn't open file");
	$data=array();
	$i=0;
	while($file=fgets($read,4096)){
		if($n && $i>$n)break;
		$astr=explode(",",iconv('GB2312','UTF-8',  trim($file)));
		$str="";
		foreach ($astr as $val) {
			if($i==0)$str.=$val.",";else$str.="'".$val."',";
		}
		$data[$i]=substr($str, 0,-1);
		$i++;
	}
	return $data;
}
function lline($str){
	return str_replace("\n", "<br>", $str);
}
function check_sdx($sdxdata,$callback=null){
	if($sdxdata->status=="100" && $callback){$_SESSION["_P"]=null;echo $sdxdata->$callback;}
	if($sdxdata->status>100 && $callback)echo "-".$sdxdata->status;
	if($sdxdata->status<100){
		if($callback)echo str_replace("<br>", "\n", $sdxdata->error_message);
		if($sdxdata->status<0)error("[php_visit],userid=".$_SESSION["user"]->uid.",status=".$sdxdata->status.",error_message=".$sdxdata->error_message,"");	
	}
	if($callback)exit;
}
?>
